var inTransition=false;var isLoaded=false;var fdJSON='';var fdExpiration
function updateFreshestDeal(){var freshdeal=eval('('+fdJSON+')').result;for(var obj in freshdeal)if(isNaN(obj)){if(obj=='url'){var deal_url=freshdeal[obj];if(deal_url==false||deal_url=="false")deal_url="deals.html";fdurl=deal_url}}else fd=freshdeal[obj];$('#freshestdeal_image_link').attr('href',fdurl);$('#freshestdeal_url').attr('href',fdurl).html(trimWithElipses(fd.name));$('#freshestdeal_go_btn').attr('href',fdurl);$('#freshestdeal_image').attr('src',fd.imagepath).attr('alt','Image of '+fd.name);$('#freshestdeal_price').html("$"+fd.price);$('#freshestdeal_compare_price').html('$'+fd.compprice);bdp=fd.end.split(' ');ldp=bdp[0].split('-');ltp=bdp[1].split(':');sendtm=new Date(ldp[0],ldp[1]-1,ldp[2],ltp[0],ltp[1],ltp[2],0);bdp=fd.current_dttm.split(' ');ldp=bdp[0].split('-');ltp=bdp[1].split(':');scurtm=new Date(ldp[0],ldp[1]-1,ldp[2],ltp[0],ltp[1],ltp[2],0);msLeft=sendtm-scurtm;var s=Math.floor(msLeft/1000);fdExpiration=new Date();fdExpiration.setSeconds(fdExpiration.getSeconds()+s)}
function trimWithElipses(bigString){if(bigString.length>65){var lilString=bigString.substring(0,65);lilString=lilString.substring(0,lilString.lastIndexOf(' '))+'...';bigString=lilString};return bigString};$(document).ready(function(){$.ajax({type:"POST",url:"/freshestdeal/getfreshestdeal",data:"ajax=true",success:(function(data){fdJSON=data;updateFreshestDeal();$('.freshest-deal').css("visibility","visible")})});setInterval(function(){if(!inTransition){var now=new Date();var ms=fdExpiration-now;if(ms>=0){var s=Math.ceil(ms/1000);var ss=s%60;s-=ss;s=s/60;var mm=s%60;var hh=(s-mm)/60;var display=((hh>9)?''+hh:'0'+hh)+":"+((mm>9)?''+mm:'0'+mm)+":"+((ss>9)?''+ss:'0'+ss);$('#freshestdeal_timer').html(display)}else{inTransition=true;$('#freshestdeal_timer').html('00:00:00')}}else if(fdJSON==''){$.ajax({type:"POST",url:"/freshestdeal/getfreshestdeal",data:"ajax=true",success:(function(data){fdJSON=data})});$('.freshest-deal').fadeTo("slow",0.01)}else{updateFreshestDeal();$('.freshest-deal').fadeTo("slow",1.0);inTransition=false;fdJSON=''}},1000)});$(function(){chapterAds.init()});var chapterAds={init:function(){$('.chapter-ads .chapters a').each(function(i){$(this).click(function(e){$('.chapter-ads div.ad').fadeOut().eq(i).fadeIn('slow');chapterAds.j=i;chapterAds.j++;$(this).addClass('active').siblings().removeClass('active')})});chapterAds.cycle()},cycle:function(){if(chapterAds.j>=$('.chapter-ads .chapters a').length)chapterAds.j=0;$('.chapter-ads .chapters a:eq('+chapterAds.j+')').trigger('click')},j:0};window.setInterval("chapterAds.cycle()",8000);$(function(){$('.like-it,.likes a').click(function(e){$(this).css('background-position','0 0')});$('.show-answer').toggle(function(e){e.preventDefault();$(this).html('<a class="show-answer" href="#">Hide Answers</a>').parent().parent().parent().parent().parent().parent('.q-container').next('.answer-container').fadeIn('slow')},function(e){e.preventDefault();$(this).html('<a class="show-answer" href="#">View Answers</a>').parent().parent().parent().parent().parent().parent('.q-container').next('.answer-container').fadeOut('slow')}).each(function(i){if(i<1)$(this).trigger('click')});$('.questions .q-container .be-the-first a').click(function(e){e.preventDefault();$.nyroModalManual({bgColor:'#000000',minWidth:380,width:340,height:438,url:'modules/ask-question-form/index.php'})})});$(document).ready(function(){var containerWidth=0;$('.top-brands a').each(function(i){containerWidth+=$(this).width()+10});$('.top-brands .container').width(containerWidth);var containerDeficit=(containerWidth/2)-130;loopBrands(containerDeficit)})
function loopBrands(containerDeficit){$('.top-brands .container').animate({left:0},0).animate({left:(containerDeficit*-1)},60000,"linear",function(){loopBrands(containerDeficit)})};jQuery(document).ready(function(){$(".ask_button,.ask").click(function(e){e.preventDefault();$.facebox.settings.overlay=true;link=$(this).attr('href');if(link=='#'||link=='')link="/question/form";$.ajax({type:"GET",url:link,dataType:"html",success:function(data){$.facebox(data);startQAFormJs()}})})});var questiontags=''
function startQAFormJs(){jQuery('.ask-question-form a.why').hover(function(){jQuery('.ask-question-form p.explanation').fadeIn()},function(){jQuery('.ask-question-form p.explanation').fadeOut()});$(".ask-question-form input.topic-entry").blur(function(){addTag($(this).val())});$('.submit-1').click(function(e){e.preventDefault();errors=false;$('.ask-question-form :input').css('background-color','white');if($('.ask-question-form :input[name="question"]').val()==''||$('.ask-question-form :input[name="question"]').val().length<10){$('.ask-question-form :input[name="question"]').css('background-color','#ffcccc');errors=true};if($('.ask-question-form :input[name="category"]').val()==''){errors=true;$('.ask-question-form select').css('background-color','#ffcccc')};if($('.ask-question-form :input[name="category"]').val()=='other'&&$('.ask-question-form :input[name="other_category"]').val()==''){errors=true;$('.ask-question-form :input[name="other_category"]').css('background-color','#ffcccc')};blank=0;questiontags='';$(".ask-question-form :input.topic-entry").each(function(i){if($(this).val()=='')blank=blank+1;else questiontags=questiontags+','+$(this).val()});if(blank>5){$(".ask-question-form :input.topic-entry").eq(1).css('background-color','#ffcccc');errors=true};if(errors==true){alert('Please fill out all of the required fields in red.');return};if($('.ask-question-form :input[name="category"]').val()=='other')first_tag=$('span#other_category input[name="other_category"]').val();else first_tag=$('.ask-question-form :input[name="category"]').val();$.ajax({type:"POST",url:'/question/form?ajax&step=1',data:'question='+$('.ask-question-form :input[name="question"]').val()+'&first_tag='+first_tag+'&tag_list='+questiontags+'&product_id='+$('.ask-question-form :input[name="product_id"]').val()+'&product_name='+$('.ask-question-form :input[name="product_name"]').val(),dataType:'json',success:function(data){if(data.errors.length==0){if(data.needs_login!=undefined){$.facebox("Your question will be submitted after you log in.");return};if(data.link!=undefined)window.location=data.link;$(".ask-question-form #scroll-1").html('<i>'+data.params.question+'</i>');jQuery.each(data.questions,function(i,item){$(".ask-question-form #other_questions").append('<a href="'+item.link+'" class="link">'+item.question+'</a>')});$('.step-1').hide();$('.step-2').show()}else error_alert(data.errors)}})});$('.submit-2').click(function(e){e.preventDefault();if($('.ask-question-form :input[name="category"]').val()=='other')first_tag=$('span#other_category input[name="other_category"]').val();else first_tag=$('.ask-question-form :input[name="category"]').val();$.ajax({type:"POST",url:'/question/form?ajax&step=2',data:'question='+$('.ask-question-form :input[name="question"]').val()+'&first_tag='+first_tag+'&tag_list='+questiontags+'&product_id='+$('.ask-question-form :input[name="product_id"]').val()+'&product_name='+$('.ask-question-form :input[name="product_name"]').val(),dataType:'json',success:function(data){if(!data.error){if(data.needs_login!=undefined){$.facebox("Your question will be submitted after you log in.");return};$.facebox.close();if(data.link!=undefined)window.location=data.link;return}else error_alert(data.errors)}})});$('.cancel').click(function(e){e.preventDefault();$.facebox.close()})}
function error_alert(errors){error_list="We found the following errors:\n";jQuery.each(errors,function(i,item){error_list=error_list+item+"\n"});alert(error_list)}
function trim(str){var str=str.replace(/^\s\s*/,''),ws=/\s/,i=str.length;while(ws.test(str.charAt(--i)));return str.slice(0,i+1)}
function addTag(text){text=trim(text);if(text=='')return;dupe_count=0;$(".ask-question-form input.topic-entry").each(function(i){if(trim($(this).val())==text){dupe_count=dupe_count+1;clear_this=$(this)}});if(dupe_count>1){alert('You have already selected that tag.  Please choose again.');clear_this.val('')}}
function findValue(li){if(li==null)return alert("No match!");if(!!li.extra)var sValue=li.extra[0];addTag(li.innerHTML)}
function selectItem(li){findValue(li)}
function formatItem(row){return row[0]}
function other_switch(){if($('.ask-question-form select#cat_pulldown').val()=='other')$('span#other_category').show();else{$('span#other_category input[name="other_category"]').val('');$('span#other_category').hide()}};$(function(){$('.like-it,.likes a').click(function(e){$(this).css('background-position','0 0')})})